package com.lipaluma.xml.mapping;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.lang.BooleanUtils;

import com.lipaluma.field.mapper.AutomaticFieldMapper;
import com.lipaluma.field.mapper.multiple.MultipleFieldMapper;

@XmlRootElement(name=XmlMultiplePathesMapping.MULTIPLE_PATHES)
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlMultiplePathesMapping extends AbstractXmlFieldMapping {
	public static final String MULTIPLE_PATHES = "multiple-pathes";

	@XmlElementWrapper
	@XmlElement(name="path")
	private String[] pathes;

	@XmlAttribute
	private Class<? extends MultipleFieldMapper> with;
	@XmlAttribute(name="mandatory-presence")
	private Boolean presenceMandatory;

	public String[] getPathes() {
		if(pathes == null)
			return new String[0];
		return pathes;
	}
	
	@Override
	public Class<? extends MultipleFieldMapper> with() {
		if(with == null)
			return AutomaticFieldMapper.class;
		return with;
	}

	@Override
	public boolean isMultiple() {
		return true;
	}
	
	public boolean isPresenceMandatory() {
		return BooleanUtils.toBoolean(presenceMandatory);
	}

}
